<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>用户列表 - 深蓝汇网站管理</title>
    {include file="innerend/common/meta" /}
</head>
<body>

<!--- 面包屑 --->
<!--- <nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 用户管理
    <span class="c-gray en">&gt;</span>用户列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav> --->

<div class="page-container">
    {if(!empty($search))}
        <div class="text-c">
            {foreach($search as $_search)}
                <input type="text" name="{$_search}" id="{$_search}" placeholder=""
                       value="{$request[$_search]??''}" style="width:250px;"
                       class="input-text"/>
            {/foreach}
            <button name="btnSearch" onclick="page=1;getPage();" class="btn btn-success" type="button">
                <i class="Hui-iconfont">&#xe665;</i> 立即搜索
            </button>
        </div>
    {/if}

    <div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" onclick="articleEdit(0)" class="btn btn-danger radius">添加用户</a>
            <a href="javascript:;" onclick="batchOp('delUsers');" class="btn btn-danger radius">删除</a>
			<a href="javascript:;" onclick="batchOp('addJifen');" class="btn btn-danger radius" id="addJifen">加分</a>
			<a href="javascript:;" onclick="batchOp('reduceJifen');" class="btn btn-danger radius"
               id="reduceJifen">减分</a>
			<a style="display:none;" href="javascript:;" onclick="batchOp('shenhe');"
               class="btn btn-danger radius">审核</a>
			<a style="display:none;" href="javascript:;" onclick="batchOp('quxiaoshenhe');"
               class="btn btn-danger radius">取消审核</a>
			<a href="javascript:;" onclick="batchOp('xitongxiaoxi');" class="btn btn-danger radius" id="xitongxiaoxi">发送系统消息</a>
		</span>
        <span class="r">共有：<strong id="totalNums">0</strong> 条</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-hover">
            <thead>
            <tr class="text-c">
                <th width="25"><input type="checkbox" id="checkAll" name="" value=""></th>
                <th>用户名</th>
                <th width="80">类型</th>
                <th width="120">媒体</th>
                <th width="50">认证</th>
                <th width="200">组织名称</th>
                <th width="100">真实姓名</th>
                <th width="50">积分</th>
                <th width="120">注册时间</th>
                <th width="120">最后登录时间</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
        <div class="page"></div>
    </div>
</div>

<script type="text/javascript">
    var layerIdx;
    var page = 1;
    var sType = "{sp:I('get.sType')}";
    var type = "{sp:I('get.type')}";

    var jifen = 0;//加减 成功后清0
    var xitongxiaoxi = '';//系统消息


    $(document).ready(function (e) {
        getPage();
    });

    function getPage() {
        var keyword = $("#keyword").val();

        $.ajax({
            beforeSend: function () {
                layerIdx = layer.load();
            },
            type: "POST",
            async: false,
            dataType: "json",
            url: "{sp:U('API/Users/getUsersPage')}",
            data: {
                keyword: keyword,
                type: type,
                sType: sType,
                r: Math.random()
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {

            },
            success: function (ret) {
                if (ret.status) {
                    $("#totalNums").text(ret.nums);
                    if (ret.pages > 0) {
                        laypage({
                            cont: $('.page'), //容器。值支持id名、原生dom对象，jquery对象,
                            pages: ret.pages, //总页数
                            skip: ret.pages > 10 ? true : false, //是否开启跳页
                            skin: '#AF0000',
                            groups: 6, //连续显示分页数
                            curr: 1,
                            jump: function (obj, first) { //触发分页后的回调
                                page = obj.curr;
                                getList();
                            }
                        });
                    } else {
                        layer.msg("暂无记录");
                        $(".table tbody,.page").html("");
                    }
                }
            },
            complete: function () {
                layer.close(layerIdx);
            }
        });
    }

    function getList() {
        var keyword = $("#keyword").val();

        $.ajax({
            beforeSend: function () {
                layerIdx = layer.load();
            },
            type: "POST",
            async: false,
            dataType: "json",
            url: "{sp:U('API/Users/getUsersList')}",
            data: {
                page: page,
                keyword: keyword,
                type: type,
                sType: sType,
                r: Math.random()
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {

            },
            success: function (ret) {
                if (ret.status) {
                    render(ret.data);
                }
            },
            complete: function () {
                layer.close(layerIdx);
            }
        });
    }

    function render(data) {
        var tmpl = "";
        for (var i = 0; i < data.length; i++) {
            tmpl += '<tr class="text-c">'
                + '	<td><input type="checkbox" value="' + data[i].id + '" name="id" /></td>'
                + '	<td class="text-l" title="点我修改" onclick="articleEdit(' + data[i].id + ')">' + data[i].sUserName + '</td>'


            tmpl += '	<td>' + data[i].sType + '</td>'
                + '	<td>' + data[i].sMeiTi + '</td>'
                + '	<td>' + ((data[i].bPass == 1 && data[i].sShenQingType != '') ? "<span class=''>已认证</span>" : "<span class=''>未认证</span>") + "<br/><a href='javascript:;' onclick='renzhen(" + data[i].id + ")'>认证资料</a></td>";

            tmpl += '	<td>' + data[i].sQiYeMingCheng + '</td>'


            tmpl += '	<td>' + data[i].sXingMing + '</td>'
                + '	<td>' + data[i].jifen + '</td>'
                + '	<td>' + data[i].dtTime + '</td>'
                + '	<td>' + data[i].dtLast + '</td>'
                + '</tr>';
        }
        $(".table tbody").html(tmpl);
    }

    function articleEdit(id) {
        var index = layer.open({
            type: 2,
            title: (id == 0 ? '添加' : '编辑') + "用户",
            content: "{sp:U('Manage/Users/add')}?id=" + id
        });
        layer.full(index);
    }

    function renzhen(id) {
        var index = layer.open({
            type: 2,
            title: "认证",
            content: "{sp:U('Manage/Users/renzhen')}?id=" + id
        });
        layer.full(index);
    }

    function batchOp(type) {
        var txt = '';
        switch (type) {
            case "reduceJifen":
                if (jifen > 0) {
                    txt = '确认要减少积分？'
                } else {
                    editJifen('reduceJifen');
                    return;
                }
                break;
            case "addJifen":
                if (jifen > 0) {
                    txt = '确认要增加积分？'
                } else {
                    editJifen('addJifen');
                    return;
                }
                break;
            case "shenhe":
                txt = '确认要审核？'
                break;
            case "quxiaoshenhe":
                txt = '确认要取消审核？'
                break;
            case "delUsers":
                txt = '确认要删除？'
                break;
            case "xitongxiaoxi":
                if (xitongxiaoxi != '') {
                    txt = '确认要发送系统消息？'
                } else {
                    xitongxiaoxiFunc();
                    return;
                }
                break;
        }
        var ids = '';
        $("input[name='id']:checked").each(function () {
            ids += $(this).val() + ',';
        });
        if (ids == '') return;
        layer.confirm(txt, function (index) {
            layer.closeAll('dialog');
            $.ajax({
                beforeSend: function () {
                    layerIdx = layer.load();
                },
                type: "POST",
                async: false,
                dataType: "json",
                url: "{sp:U('API/Users/batchOp')}",
                data: {
                    ids: ids,
                    type: type,
                    jifen: jifen,
                    xitongxiaoxi: xitongxiaoxi,
                    r: Math.random()
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {

                },
                success: function (ret) {
                    if (ret.status) {
                        jifen = 0;
                        xitongxiaoxi = '';
                        layer.closeAll();
                        getList();
                        //$("#checkAll").click();
                    }
                },
                complete: function () {
                    layer.close(layerIdx);
                }
            });
        });
    }

    //
    function editJifen(type) {
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '240px'], //宽高
            content: '<div id="chooseClass">'
                + '<input type="text" value="" id="jifen" class="input"/>'
                + '<a href="javascript:;" onclick="doClick(\'' + type + '\');" class="btn btn-success radius">确认</a>'
                + '</div>'
        });
    }

    function doClick(type) {
        jifen = $('#jifen').val();
        layer.closeAll();
        console.log(jifen);
        $("#" + type).click();
    }

    //设置权限
    function xitongxiaoxiFunc() {
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['420px', '240px'], //宽高
            content: '<div id="chooseClass">'
                + '<input type="text" value="" id="re_xitongxiaoxi" class="input"/>'
                + '<a href="javascript:;" onclick="doXiaoxiClick();" class="btn btn-success radius">确认</a>'
                + '</div>'
        });
    }

    function doXiaoxiClick() {
        xitongxiaoxi = $('#re_xitongxiaoxi').val();
        layer.closeAll();
        $('#xitongxiaoxi').click();
    }
</script>

</body>
</html>
